<template>

  <div id="app">

    <input type="file" class="file">
    <el-button size="small" @click="readFile">读取</el-button>

  </div>

</template>

<script>
  export default {
    name: 'icons',
    methods: {
      readFile() {
        let fileselect = document.querySelector('input[type=file]').files[0]
        //找到文件上传的元素
        let reader = new FileReader()
        if (typeof FileReader === 'undefined') {
          alert('您的浏览器不支持FileReader接口')
        }
        reader.readAsText(fileselect, 'gb2312')
        //注意读取中文的是用这个编码，不是utf-8
        reader.onload = function() {
          let iconCss = reader.result
          let iconList = []
          const reg = /(xp-icon\-.*)\:before/g
          //筛选icon-开头:before结尾的字符串 期中/(icon\-.*)代表icon-加任意字符的分组
          let resultS
          while ((resultS = reg.exec(iconCss)) != null) {
            //遍历出分组的数据是我们需要的
            iconList.push(resultS[1].substr(8))
            //我们需要的格式
          }
          console.log(`共${iconList.length}个`,JSON.stringify(iconList))
        }
      }
    }
  }

</script>

<style scoped>

</style>
